<?php
/**
 * 扫描相关获取订单详情
 * User: poptser@foxmail.com
 * Date: 2018/3/28
 * Time: 10:54
 */

namespace App\Services\Sorting;

use Illuminate\Support\Facades\DB;


class ScanService{


    /**
     * 转换摄像头所获得的条件
     * Author:poptser@foxmail.com
     * @param $cameraInput
     * @return mixed
     */
    public function convertFilter($cameraInput){

        $filter = [];
        if(is_numeric($cameraInput)){
            //纯数字，摄像头扫描
            if(strlen($cameraInput) > 9){
                //扫出订单ID大于9，按订单编号查询
                if(strlen($cameraInput) > 19){
                    //扫出订单ID大于19，按订单编号加分袋信息查询
                    $orderSn = substr($cameraInput, 0, 19);
                    $filter[] = ['order_sn', '=', $orderSn];
                }else{
                    if(strlen($cameraInput) == 13){
                        $order_number = substr($cameraInput, 0, 8);
                        $filter[] = ['order_sn', 'like', "%".$order_number];
                    }else{
                        $filter[] = ['order_sn', '=', $cameraInput];
                    }
                }
            }else{
                $filter[] = ['order_id', '=', $cameraInput];
            }
        }else{
            //手动输入 s12345678
            $order_number = substr($cameraInput, 1, 8);
            $filter[] = ['order_sn', 'like', "%".$order_number];
        }

        return $filter;
    }

    /**
     * 获取订单ID
     * Author:poptser@foxmail.com
     * @param null $filter
     * @return bool|mixed
     */
    public function getOrderId($filter = null){
        if(empty($filter)){
            return false;//条件为空，不查询
        }
        return DB::table("order_info")->where($filter)->value('order_id');
    }


}